package com.rabbitmq.workqueue;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.rabbitmq.client.Delivery;
import com.rabbitmq.util.ConnectionUtils;

import java.io.IOException;


/**
 * @author yinxing
 * 一个工作线程
 * @date 2022-08-29
 */
public class Consumer3 {

    //队列名字
    private final static String QUEUE_NAME = "hello";

    public static void main(String[] args) throws IOException {
        Channel channel = ConnectionUtils.getChannel();

        DeliverCallback deliverCallback = (String consumerTag, Delivery message) -> {
            System.out.println("Consumer3接收到:" + new String(message.getBody()));
            channel.basicAck(message.getEnvelope().getDeliveryTag(),false);
        };
        CancelCallback cancelCallback = (String consumerTag) -> {
            System.out.println(consumerTag + "Consumer3取消消息");
        };
        System.out.println("Consumer3等待接收....");
        channel.basicConsume(QUEUE_NAME, false, deliverCallback, cancelCallback);
    }

}
